﻿using PlatformUW.Contracts;
using PlatformUW.Entities;
using PlatformUW.Entities.RequestFeatures;
using PlatformUW.EntityFramework.Repositories.Extensions;

namespace PlatformUW.EntityFramework.Repositories
{
    public class SensorRepository : Repositories<SensorTable, Guid>, ISensorRepository
    {
        public SensorRepository(PlatformDBContext repositoryContext) : base(repositoryContext)
        {
            
        }

        public Task<PagedList<SensorTable>> GetAllSensorsAsync(SensorParameter parameter)
        {
            return Task.FromResult( GetAll()
                .Where(sensor => sensor.DateCreated >= parameter.MinDateCreated && sensor.DateCreated <= parameter.MaxDateCreated)
                .FilterByName(parameter.Name)
                .OrderByQuery(parameter.QueryString)
                .ToPagedList(parameter.PageNumber, parameter.PageSize));
        }


        public PagedList<SensorTable> GetAllSensors(SensorParameter parameter)
        {
            return GetAll().Where(sensor => sensor.DateCreated >= parameter.MinDateCreated && sensor.DateCreated <= parameter.MaxDateCreated)
                .FilterByName(parameter.Name)
                .OrderByQuery(parameter.QueryString)
                .ToPagedList(parameter.PageNumber, parameter.PageSize);
        }
    }
}
